﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data;
using ZHDJ.Data.DataCaching;
using ZHDJ.WebPage;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.PortalParts
{
    public partial class PageMoreBranch1 : MorePageMaster
    {
        /// <summary>
        /// 工作室ID
        /// </summary>
        private string BranchID
        {
            get
            {
                return this.Request["BranchID"] ?? "";
            }
        }

        public string ImgUrl { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {

            LoadData();

        }

        /// <summary>
        /// 加载
        /// </summary>
        public void LoadData()
        {
            using (var DB = new DBInstance().DB)
            {
                var branch = DB.PartyOrgBranchs.Find(BranchID);
                if (branch == null)
                {
                    //RedirectToDefault();
                    branchInformation.Style["display"] = "none";
                    branchLogo.Style["display"] = "none";
                }
                else
                {
                    branchInformation.Style["display"] = "block";
                    branchLogo.Style["display"] = "block";
                    this.litBranchName.Text = string.Format(" <a href='../BranchIndex.aspx?BranchID={0}' class='abranchname'>{1}</a>", BranchID, branch.BranchName);
                    ImgUrl = branch.ImageUrl;
                }
            }
            imgBranch.ImageUrl = UpFileBusiness.GetFileUrl(ImgUrl);

            //打不到模块
            if (string.IsNullOrEmpty(Module))
            {
                RedirectToDefault();
            }

            var moduleQuery = PartyModuleNavigationCaching.Get(Module);

            var m = moduleQuery.FirstOrDefault(a => string.IsNullOrEmpty(a.Category));
            if (m == null)
            {
                RedirectTo("Login", "~/default.aspx");
            }
            litModuleName.Text = ModuleName = m.PageName;
            var q = moduleQuery.Where(a => a.Enabled && !string.IsNullOrEmpty(a.Category));
            rptPage.DataSource = q.ToList();
            rptPage.DataBind();

            hdCategory.Value = Category;
        }
        public string GetUrl(string url)
        {
            var temp = url;
            if (temp.IndexOf('?') > 0)
            {
                temp = temp + "&BranchID=" + this.BranchID;
            }
            else
            {
                temp = temp + "?BranchID=" + this.BranchID;
            }
            return temp;
        }
    }
}